package pos.domain;

import java.sql.Date;
import java.util.List;

import pos.data.*;

public class SalesAdminister {
	
	private static SalesAdminister sa;
	private List<Sale> sales;
	
	private SalesAdminister () {
		this.sales = (new JDBCSaleDAO().selectSales());
	}
	
	public static synchronized SalesAdminister getInstance () {
		if (sa == null)
            sa = new SalesAdminister();
        return sa;		
	}
	
	public List<Sale> getSales() {
		return sales;
	}
	
	public void insertNewSale (Product prod, String quant, Date limit, String price) {
		ISaleDAO sdao = new JDBCSaleDAO();
		Sale venta = new Sale();
		venta.setActive(true);
		venta.setLimitDate(limit);
		venta.setPrice(price);
		venta.setProductID(prod.getProductID());
		venta.setQuantity(quant);
		sdao.insertSale(venta);
		
	}

	public void insertNewProduct (String name, String description, String userid, String categoryName) {
		IProductDAO pdao = new JDBCProductDAO();
		Product prod = new Product();
		prod.setDescription(description);
		prod.setName(name);
		prod.setProductorID(userid);
		pdao.insertProduct(prod);		
	}
}
